//
//  BindCompanyViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/25.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "BindCompanyViewController.h"

#import "HttpRequest.h"
#import "RDVTabBarController.h"
#import "UIViewExt.h"
#import "ZJSwitch.h"
#import "CategoryListViewController.h"
#import "LoginCompanysViewController.h"
#import "ChooseCertificationStatusViewController.h"
@interface BindCompanyViewController ()<UITextFieldDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UIScrollViewDelegate,CategoryListViewControllerDelegate>
@property (retain,nonatomic)NSString *companyId;
@end
@implementation BindCompanyViewController

{
    MBProgressHUD *progressHud;
    UIButton* login;
    UILabel* companyNameLabel;
    UIButton*companyNameLabel1;
    NSMutableArray*companyIdArray;
    NSMutableArray*companyNameArray;
}
@synthesize alt = alt;
@synthesize mDelegate;
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    self.view.backgroundColor=[UIColor whiteColor];
    CGRect backframe = CGRectMake(0,0,33,33);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;

}
-(void)viewDidLoad{
    [super viewDidLoad];
    self.title = @"选择门店";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    companyIdArray=[[NSMutableArray alloc]init];
    companyNameArray=[[NSMutableArray alloc]init];
    [self initView];
   
}

- (void)initView
{
    for (NSDictionary* dicc in self.DataLine )
    {
        [companyIdArray addObject:[dicc valueForKey:@"scId"]];
        [companyNameArray addObject:[dicc valueForKey:@"companyName"]];
    }
    if (companyIdArray.count>0) {
          self.companyId=companyIdArray[0];
    }
  
    companyNameLabel=[[UILabel alloc]initWithFrame:CGRectMake(20, 60/2+64, 140, 44)];
    companyNameLabel.text=[NSString stringWithFormat:@"门店名称"];
    companyNameLabel.textColor=shenhuiColor;
    companyNameLabel.font=[UIFont systemFontOfSize:15];
    [self.view addSubview:companyNameLabel];
     companyNameLabel1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-260,  60/2+64,225,44)];
    [companyNameLabel1 setTitle:nil forState:UIControlStateNormal];
    companyNameLabel1.titleLabel.font=[UIFont systemFontOfSize:15];
    [companyNameLabel1 setTitle:[[self.DataLine objectAtIndex:0]objectForKey:@"companyName"] forState:UIControlStateNormal];

    companyNameLabel1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [companyNameLabel1 addTarget:self action:@selector(GPRSAddress:) forControlEvents:UIControlEventTouchUpInside];
    [companyNameLabel1 setTitleColor:luseColor forState:UIControlStateNormal];
    [self.view addSubview:companyNameLabel1];
    UIButton*jiantouBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40,60/2+7+64, 30, 30)];
    [jiantouBtn setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
    [jiantouBtn addTarget:self action:@selector(GPRSAddress:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:jiantouBtn];
 
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(10,148/2+64, ScreenWidth-20, 0.25)];
    line1.backgroundColor = qianhuiColor;
    [self.view addSubview:line1];
    [self loginBtn];
    
}
-(void)GPRSAddress:(UIButton*)sender{

    CategoryListViewController*de = [[CategoryListViewController alloc] init];
    de.code =companyIdArray;
    de.content=companyNameArray;
    de.sat=@"companyName";
    de.mDelegate=self;
    [self.navigationController pushViewController:de animated:YES];



}
-(void)EarnestRate:(NSString *)EarnestRate EarnestRateCode:(NSString *)EarnestRateCode{
    self.companyId=EarnestRateCode;
  [companyNameLabel1 setTitle:EarnestRate forState:UIControlStateNormal];
}

-(void)login:(UIButton *)sender{

    if ([companyNameLabel1.titleLabel.text length] <1)
    {
        [self showAlertMessage:@"请选择门店"];
    }
    else{
        
  
        ChooseCertificationStatusViewController *generateVC=[[ChooseCertificationStatusViewController alloc] init];
     
        generateVC.userName=self.userName;
        generateVC.sex=self.sex;
        generateVC.scId=self.companyId;
        [self.navigationController pushViewController:generateVC animated:YES];

        
        
        }
}
-(void)loginBtn{
    [login removeFromSuperview];
    login = [[UIButton alloc] initWithFrame:CGRectMake(10, 525/2, ScreenWidth-20, anniuHeigth)];
    [login setTitle:@"选择身份" forState:UIControlStateNormal];
    [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    if (companyNameLabel1.titleLabel.text.length == 0) {
        
        [login.layer setCornerRadius:3.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){228/255.0, 228/255.0, 228/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        login.backgroundColor=qianhuiColor;
        [self.view addSubview:login];
    }if (companyNameLabel1.titleLabel.text.length >1) {
        
        login.backgroundColor=luseColor;
        [login.layer setCornerRadius:3.0]; //设置矩圆角半径
        [login.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){23/255.0, 148/255.0, 152/255.0, 1.0});
        [login.layer setBorderColor:tureBTncolorref];//边框颜色
        [login addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:login];
    }
}



- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定哦 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
